<?php
// Manage categroy list
class CategoryList
{
	/* Public variables available in category_list.tpl Smarty template */
	public $mCategories;
	public $mSelectedCategory = 0;
	
	public function __contruct()
	{
        if(!isset($_GET['MerchandiseId']))
        { 
		    if (isset($_GET['CategoryId']))
			    $this->mSelectedCategory = (int)$_GET['CategoryId'];
        }
        else
        {    
            $continue_shopping = Link::QueryStringToArray($_SESSION['link_to_continue_shopping']);
            if (array_key_exists('CategoryId', $continue_shopping))
                $this->mSelectedDepartment = (int)$continue_shopping['CategoryId'];
            else
                trigger_error('CategoryId not set');
                
            if (array_key_exists('CategoryId', $continue_shopping))
                $this->mSelectedCategory = (int)$continue_shopping['CategoryId'];
        }
	}
	
	public function init()
	{
		$this->mCategories = Catalog::GetAllCategories();
		
		for ($i = 0;$i < count($this->mCategories);$i++)
			$this->mCategories[$i]['link_to_category'] = Link::ToCategory($this->mCategories[$i]['category_id']);
	}
}
?>